package jmine.tec.web.front.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import jmine.tec.persist.annotation.Alias;
import jmine.tec.persist.annotation.Constraint;
import jmine.tec.persist.annotation.Index;

import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.Type;
import org.hibernate.validator.NotNull;

import bancosys.tec.component.Documentation;
import bancosys.tec.persist.bussobj.PersistableBusinessObject;
import bancosys.tec.utils.date.Timestamp;

/**
 * A command type, dictates how to deal with the command.
 * 
 * @author lundberg
 */
@Entity
@Alias("BORQRV")
@Table(name = "BACK_OFFICE_REQUEST_REVISION")
@Documentation("REVISAO DE REQUISICAO AO BACK OFFICE.")
@SequenceGenerator(sequenceName = "SEQ_BORQRV", name = "SEQ_BORQRV")
public class BackOfficeRequestRevision extends PersistableBusinessObject {

    private static final int COMMENT_LENGTH = 512;

    private Long id;

    private BackOfficeRequest request;

    private String user;

    private Timestamp timestamp;

    private BackOfficeRequestRevisionOutcome outcome;

    private String comment;

    /**
     * @return the id
     */
    @Id
    @GeneratedValue(generator = "SEQ_BORQRV")
    @Column(name = "COD_REQUEST_REVISION", nullable = false)
    @Documentation("CODIGO DA REVISAO DE REQUISICAO AO BACK OFFICE")
    public Long getId() {
        return this.id;
    }

    /**
     * @return the request
     */
    @Index(suffix = "JT_0")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "COD_BACK_OFFICE_REQUEST", nullable = false)
    @Documentation("CODIGO DA REQUISICAO REVISADA.")
    public BackOfficeRequest getRequest() {
        return this.request;
    }

    /**
     * @return the user
     */
    @NotNull
    @Column(name = "USU_REV", nullable = false)
    @Documentation("NOME DO USUARIO QUE FEZ A REVISAO.")
    public String getUser() {
        return this.user;
    }

    /**
     * @return the timestamp
     */
    @NotNull
    @Documentation("HORA DA REVISAO DA REQUISICAO.")
    @Column(name = "TS", nullable = false)
    @Type(type = "bancosys.tec.persist.hibernate.type.TimestampType")
    public Timestamp getTimestamp() {
        return this.timestamp;
    }

    /**
     * @return the outcome
     */
    @NotNull
    @Constraint(suffix = "JT_0")
    @Column(name = "REVISION_OUTCOME", nullable = false)
    @Documentation("RESULTADO DE UMA REVISAO DE REQUISICAO.")
    public BackOfficeRequestRevisionOutcome getOutcome() {
        return this.outcome;
    }

    /**
     * @return the comment
     */
    @Column(name = "REVISION_COMMENT", length = COMMENT_LENGTH)
    @Documentation("OBSERVACOES FEITAS DURANTE A REVISAO.")
    public String getComment() {
        return this.comment;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param request the request to set
     */
    public void setRequest(BackOfficeRequest request) {
        this.request = request;
    }

    /**
     * @param user the user to set
     */
    public void setUser(String user) {
        this.user = user;
    }

    /**
     * @param timestamp the timestamp to set
     */
    public void setTimestamp(Timestamp timestamp) {
        this.timestamp = timestamp;
    }

    /**
     * @param outcome the outcome to set
     */
    public void setOutcome(BackOfficeRequestRevisionOutcome outcome) {
        this.outcome = outcome;
    }

    /**
     * @param comment the comment to set
     */
    public void setComment(String comment) {
        this.comment = StringUtils.abbreviate(comment, COMMENT_LENGTH);
    }

}
